import { Vec3, } from "cc"
import { EffectEnum, EffectManager } from "../common/EffectManager"
import { skillList } from "./skillList"
import { AttrChangedType } from "./AttrChangedType"
import { BattleBuffEnum } from "./BattleBuffEnum"


export class Skill {
    id: number
    name: string
    fee: number
    baseValue: { type: number, val: number }
    change: number
    attackMode: number
    nature: number
    tid: number
    desc: string

    static create(data): Skill {
        let s = new Skill()
        s.id = data.id
        s.name = data.name
        s.fee = data.fee
        s.baseValue = data.baseValue
        s.change = data.change
        s.attackMode = data.attackMode
        s.nature = data.nature
        s.tid = data.tid
        s.desc = data.desc

        return s
    }

    /**
     * 根据英雄heroId，查找改英雄的技能
     * @param heroId 
     * @returns 
     */
    static getListByHeroId(heroId:number): Skill[]{
        let list:Skill[] = []
        for (let item of skillList) {
            if(item.id.indexOf(heroId + '') == 0 && item.id.length >= 5){
                let s = Skill.create(item)
                list.push(s)
            }
            
            
        }
        return list
    }



    static getSkillArray() {
        let obj = {}
        for (let item of skillList) {
            let s = Skill.create(item)
            obj[s.id] = s
        }
        return obj
    }

    static async playSkill(start: Vec3, end: Vec3, isBang:boolean) {
        if(isBang){
            await EffectManager.instance.playShoot(EffectEnum.BigFire, start, end, 0.5)
        } else {
           
            await EffectManager.instance.playShoot(EffectEnum.Fire, start, end, 0.5)
        }
    }

    static async playAddition(pos: Vec3){
        await EffectManager.instance.playOnce(EffectEnum.HongYu, pos, 0.5)
    }

    

    static async hurt(pos: Vec3, type:number){
        let url = ''
        switch (type){
            case AttrChangedType.Miss:
                // return "闪避";
                url = EffectEnum.YunChen
                break
            case AttrChangedType.Parry:
                // return "格挡";
                url = EffectEnum.GeDang
                break
            case AttrChangedType.Bang:
                // return "暴击";
                url = EffectEnum.Baozha
                break
            case AttrChangedType.Damage:
                // return "普通攻击";
                url = EffectEnum.PuTongBaoZha
                break
            case AttrChangedType.Reflect:
                // return "反弹伤害";
                break
            case AttrChangedType.Encourage:
                // return "鼓舞";
                break
            case AttrChangedType.Depression:
                // return "沮丧";
                break
            case AttrChangedType.Absorb:
                // return "吸收";
                url = EffectEnum.HongDun
                break
            case AttrChangedType.Recover:
                // return "恢复";
                break
            case AttrChangedType.SelfHurt:
                // return "自残";
                break
            case AttrChangedType.Poisoned:
                // return "中毒";
                break
            case AttrChangedType.AntiFire:
                // return "避火";
                break
            case AttrChangedType.AntiWater:
                // return "避水";
                break
            case AttrChangedType.AntiWood:
                // return "避风";
                break
            default:
              
        }

        if(!url){
            url = EffectEnum.PuTongBaoZha
            return
        }
        await EffectManager.instance.playOnce(url, pos)
    }


    static async buff(pos: Vec3, type:number){
        let url = ''
        switch (type){
            case BattleBuffEnum.Confused:
                // return "混乱";
                break
            case BattleBuffEnum.Dazed:
                // return "晕眩";
                break
            case BattleBuffEnum.Poisoned:
                // return "中毒";
                url = EffectEnum.ZhongDu
                break
            case BattleBuffEnum.UnabledAction:
                // return "禁止";
                break
            case BattleBuffEnum.WindFury:
                // return "风怒";
                break
            case BattleBuffEnum.Sharp:
                // return "破甲";
                break
            case BattleBuffEnum.PaoXiao:
                // return "咆哮";
                break
            case BattleBuffEnum.Bless:
                // return "神佑";
                break
            case BattleBuffEnum.Stone:
                // return "圣盾";
                break
            case BattleBuffEnum.JiAng:
                // return "激昂";
                break
            case BattleBuffEnum.BeDead:
                // return "濒死";
                break
            case BattleBuffEnum.Dead:
                // return "死亡";
                url = EffectEnum.Dead
                break
            case BattleBuffEnum.Fire:
                // return "燃烧";
                break
            case BattleBuffEnum.AntiFire:
                // return "避火";
                break
            case BattleBuffEnum.AntiWater:
                // return "避水";
                break
            case BattleBuffEnum.AntiWood:
                // return "避风";
                break
            case BattleBuffEnum.Bang:
                // return "暴击";
                break
        }
        if(!url){
            url = EffectEnum.HongYu
            return
            
        }
        await EffectManager.instance.playOnce(url, pos)
    }

   

}

export const SkillArray = Skill.getSkillArray()